IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_ContentTypeSelectOne]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_ContentTypeSelectOne]
GO
create procedure [dbo].[cms_sp_ContentTypeSelectOne]
(
@SiteGroupId int = null,
@SiteId int = null,
@ContentTypeId int
)
as
select 
	ContentTypes.ContentTypeId as Id,
    ContentTypes.SiteId,
	ContentTypes.SiteGroupId,
	ContentTypes.SystemLanguageId,
	ContentTypes.ContentTypeName,
	ContentTypes.Description,
	ContentTypes.IsSystemType,
	ContentTypes.CreatedBy,
    ContentTypes.DateCreated,
    ContentTypes.LastUpdatedBy,
    ContentTypes.DateLastUpdated
from dbo.ContentTypes
where ContentTypes.ContentTypeId = @ContentTypeId and
	(ContentTypes.SiteGroupId is null and ContentTypes.SiteId is null) or
	(ContentTypes.SiteGroupId = @SiteGroupId and ContentTypes.SiteId is null) or
	(ContentTypes.SiteGroupId = @SiteGroupId and ContentTypes.SiteId = @SiteId)


GO

